//
//  YuleCell2.m
//  New
//
//  Created by 才诗琦 on 16/1/20.
//  Copyright © 2016年 www.lanou3g.com. All rights reserved.
//

#import "YuleCell2.h"

@implementation YuleCell2
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        //图片
        self.imag = [[UIImageView alloc] init];
        _imag.layer.cornerRadius = 5;
        _imag.clipsToBounds = YES;
        [self.contentView addSubview: _imag];
        [_imag release];
        //标题
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:18];
        [self.contentView addSubview: _titleLabel];
        [_titleLabel release];
        //内容
        self.contentLabel = [[UILabel alloc] init];
        self.contentLabel.numberOfLines = 0;
        self.contentLabel.font = [UIFont systemFontOfSize:15];
        _contentLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_contentLabel];
        [_contentLabel release];
        //评论
        self.commentCountLabel = [[UILabel alloc] init];
        self.commentCountLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_commentCountLabel];
        [_commentCountLabel release];
               
    }
    
    return self;
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.imag.frame = CGRectMake(10, 20, 100, 80);
    self.titleLabel.frame = CGRectMake(120, 20, self.contentView.frame.size.width-110, 30);
    
    CGFloat h = [[self class] heightWithText:_contentLabel.text];
    self.contentLabel.frame =CGRectMake(120, 40, self.contentView.frame.size.width-130, h);
    self.commentCountLabel.frame = CGRectMake(270, 30 + h, 120, 20);
    
    
    
}

+(CGFloat)heightWithText:(NSString *)str
{
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:17]};
    CGSize size = CGSizeMake(155, 1000);
    CGRect rect = [str boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    return rect.size.height;
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
